﻿using System;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action.admin
{
    public class deletenews : baseaction
    {
        public override void Treat()
        {
            int Id;
            if (!Int32.TryParse(GetParameter(0), out Id))
            {
                Redirect("/admin/newslist");
            }

            News news = new News();
            news.id = Id;

            if (news.Instance().Status)
            {
                Fly.Web.Resource.File img = new Fly.Web.Resource.File();
                img.FullPath = news.image;
                img.Delete();

                news.Delete();
                admin_script += "$('#msg-newsdelete').removeClass('hidden');";
            }
            else {
                admin_script += "$('#err-newsdelete').removeClass('hidden');";
            }
            Redirect("/admin/newslist");
        }
    }
}